package zy.blue7.gui;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * @author blue7
 * @version 1.0
 * @date 2022/2/22 18:19
 */
public class MainForm {
    private JPanel root;
    private JButton click;
    private JTextField from;
    private JTextField to;
    private JButton serverButton;
    private JButton clientButton;
    private JButton sendButton;

    public MainForm() {
        root.setLayout(null);
        click.addActionListener(e -> {
            System.out.println("dianjshijian");
            String text = from.getText();
            to.setText(text);
        });
        from.addKeyListener(new KeyAdapter() {
            @Override
            public void keyReleased(KeyEvent e) {
                super.keyReleased(e);
                char keyChar = e.getKeyChar();
                int keyCode = e.getKeyCode();
                System.out.println(keyChar + " : " + keyCode);
                to.setText(from.getText());
            }
        });
        serverButton.addActionListener(e -> {
            NettyServer.start();
        });
        clientButton.addActionListener(e -> {
            try {
                NettyClient.start();
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }
        });
        sendButton.addActionListener(e -> {
            NettyClient.send(to.getText());
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("MainForm");
        frame.setContentPane(new MainForm().root);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1000, 800);
        frame.setLocation(500,200);
        frame.setVisible(true);
    }
//    public static void main(String[] args) {
//        JFrame frame = new JFrame("MainForm");
//        frame.setContentPane(new MainForm().root);
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        frame.setSize(400,400);
//        frame.setLayout(null);
//        frame.setVisible(true);
//    }
}
